package cn.tedu.ivos2.geofence.controller;

import cn.tedu.ivos2.base.response.JsonResult;

import cn.tedu.ivos2.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos2.geofence.pojo.dto.GeofenceSaveDTO;
import cn.tedu.ivos2.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos2.geofence.service.GeofenceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.codec.binary.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/geofence/")
public class GeofenceController {
    @Autowired
    private GeofenceService geofenceService;

    @GetMapping("select")
    public JsonResult select(GeofenceQuery geofenceQuery){
        log.debug("电子围栏_查询条件:{}",geofenceQuery);
        List<GeofenceVO> geofenceList=geofenceService.select(geofenceQuery);
        log.debug("电子围栏_查询结果:{}",geofenceList);
        return JsonResult.ok(geofenceList);
    }

    @PostMapping("update/status/{status}/{id}")
    public JsonResult updateStatus(@PathVariable String status,@PathVariable Long id){
        log.debug("围栏_修改状态id:{},状态:{}",id,status);
        geofenceService.updateStatus(id,status);
        return JsonResult.ok();
    }

    @DeleteMapping("deleteGeo/{id}")
    public JsonResult deleteGeofence(@PathVariable Long id){
        log.debug("围栏_删除围栏的id:{}",id);
        geofenceService.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("insert")
    public JsonResult insertGeo(GeofenceSaveDTO geofenceSaveDTO){
        log.debug("围栏_新增围栏的数据:{}",geofenceSaveDTO);
        geofenceService.inset(geofenceSaveDTO);
        return JsonResult.ok();
    }

}
